
//: @"k_ttothe.com.can.cell.update.habibi.ayigu" 
Byte kCherryPiranhaRestore[] = {
    162, 41, 79, 4, 186, 174, 195, 195, 190, 195, 183, 180, 125, 178, 190, 188, 125, 178, 176, 189, 125, 178, 180, 187, 187, 125, 196, 191, 179, 176, 195, 180, 125, 183, 176, 177, 184, 177, 184, 125, 176, 200, 184, 182, 196, 254
};

//: @"chat_viptype_%ld" 
Byte kEagleMicrowaveKinnow[] = {
    9, 16, 72, 4, 171, 176, 169, 188, 167, 190, 177, 184, 188, 193, 184, 173, 167, 109, 180, 172, 131
};

//: @"chat_viptype_%lu4" 
Byte kEagleBlendWatermelon[] = {
    234, 17, 99, 4, 198, 203, 196, 215, 194, 217, 204, 211, 215, 220, 211, 200, 194, 136, 207, 216, 151, 65
};

//: @"conversationType" 
Byte kEarthwormChewPapaw[] = {
    12, 16, 2, 4, 101, 113, 112, 120, 103, 116, 117, 99, 118, 107, 113, 112, 86, 123, 114, 103, 136
};

//: @"targetId" 
Byte kSpiderScanTargetid[] = {
    117, 8, 35, 4, 151, 132, 149, 138, 136, 151, 108, 135, 244
};

//: @"messageId" 
Byte kUnpackDonkeyMessageid[] = {
    124, 9, 22, 4, 131, 123, 137, 137, 119, 125, 123, 95, 122, 123
};

//: @"com.no.num.ennory" 
Byte kBearAroniaDash[] = {
    236, 17, 1, 4, 100, 112, 110, 47, 111, 112, 47, 111, 118, 110, 47, 102, 111, 111, 112, 115, 122, 72
};

//: @"当前网络不可用，请检查你的网络设置" 
Byte kStarfruitBoaRaft[] = {
    237, 51, 33, 4, 6, 222, 180, 6, 170, 174, 8, 222, 178, 8, 220, 189, 5, 217, 174, 6, 176, 208, 8, 181, 201, 16, 221, 173, 9, 208, 216, 7, 196, 161, 7, 192, 198, 5, 222, 193, 8, 187, 165, 8, 222, 178, 8, 220, 189, 9, 207, 223, 8, 222, 207, 214
};

//: @"bubble_right_1" 
Byte kGrasshopperPapayaPack[] = {
    157, 14, 26, 4, 124, 143, 124, 124, 134, 127, 121, 140, 131, 129, 130, 142, 121, 75, 67
};

//: @"bubble_bg_%ld" 
Byte kMuleHawthornAbsorb[] = {
    60, 13, 40, 4, 138, 157, 138, 138, 148, 141, 135, 138, 143, 135, 77, 148, 140, 169
};

//: @"bubble_left_1" 
Byte kMulberryChopDeer[] = {
    72, 13, 78, 4, 176, 195, 176, 176, 186, 179, 173, 186, 179, 180, 194, 173, 127, 251
};

//: @"客服小U" 
Byte kFinchGreenAppleRun[] = {
    194, 10, 18, 4, 247, 192, 180, 248, 174, 159, 247, 194, 161, 103, 243
};

//: @"app/logo" 
Byte kPerchNectarineGrill[] = {
    67, 8, 97, 4, 194, 209, 209, 144, 205, 208, 200, 208, 248
};

//: @"normal/defaut_avatar" 
Byte kKinnowKnitOwl[] = {
    100, 20, 42, 4, 152, 153, 156, 151, 139, 150, 89, 142, 143, 144, 139, 159, 158, 137, 139, 160, 139, 158, 139, 156, 183
};

//: @"系统通知" 
Byte kPaintWolfOpalApple[] = {
    123, 12, 86, 4, 61, 9, 17, 61, 17, 245, 63, 214, 240, 61, 245, 251, 202
};

//: @"chat/normal/system_notifica" 
Byte kBoysenThrowSpider[] = {
    164, 27, 54, 4, 153, 158, 151, 170, 101, 164, 165, 168, 163, 151, 162, 101, 169, 175, 169, 170, 155, 163, 149, 164, 165, 170, 159, 156, 159, 153, 151, 23
};

//: @"已读" 
Byte kCrocodileKiwiPunch[] = {
    55, 6, 59, 4, 32, 242, 237, 35, 234, 246, 82
};

//: @"chat/normal/sendMsg_failed_tip" 
Byte kAardvarkDiceMulberry[] = {
    57, 30, 83, 4, 182, 187, 180, 199, 130, 193, 194, 197, 192, 180, 191, 130, 198, 184, 193, 183, 160, 198, 186, 178, 185, 180, 188, 191, 184, 183, 178, 199, 188, 195, 234
};

//: @"frame" 
Byte kBatDiceFrame[] = {
    194, 5, 25, 4, 127, 139, 122, 134, 126, 3
};

//
//  WQUMessageCell.m
//  ChatDemo
//
//  Created by 九月 on 1/9/25.
//

#import "WQUMessageCell.h"

//#import "RCInfoNotificationCenter.h"

#import "JVMessageNotificationCellModel.h"
#import "WQUMessageCell.h"


@interface WQUMessageCell () {
    BOOL _showPortrait;
}

@property (nonatomic, assign) BOOL showBubbleBackgroundView;
//当前 cell 正在展示的用户信息，消息携带用户信息且频发发送，会导致 cell 频发刷新
//cell 复用的时候，检测如果是即将刷新的是同一个用户信息，那么就跳过刷新
//IMSDK-2705
@property (nonatomic, strong) RCUserInfo *currentDisplayedUserInfo;

@end

@implementation WQUMessageCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];

    if (self) {
        [self rcinit];
    }

    return self;
}

- (void)rcinit {
    _showPortrait = YES;
    [self setupMessageCellView];
    [self registerMessageCellNotification];
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)setShowPortrait:(BOOL)showPortrait {
    if (showPortrait != _showPortrait) {
        _showPortrait = showPortrait;
        [self relayoutViewBy:_showPortrait];
    }

    self.portraitImageView.hidden = !_showPortrait;
}

- (BOOL)showPortrait {
    return _showPortrait;
}

#pragma mark - Super Methods

- (void)setDataModel:(JVHGMessageModel *)model {
    [super setDataModel:model];
    [self p_showBubbleBackgroundView];
    self.messageFailedStatusView.hidden = YES;
    [self p_setReadStatus];
    [self p_setUserInfo];
    [self setCellAutoLayout];
}

#pragma mark - Public Methods

- (void)updateStatusContentView:(JVHGMessageModel *)model {
    dispatch_async(dispatch_get_main_queue(), ^{
        self.messageActivityIndicatorView.hidden = YES;

        if (model.messageDirection == MessageDirection_RECEIVE) {
            return;
        }

        switch (model.sentStatus) {
            case SentStatus_SENDING:
                [self updateStatusContentViewForSending:model];
                break;

            case SentStatus_FAILED:
                [self updateStatusContentViewForFailed:model];
                break;

            case SentStatus_CANCELED:
                [self updateStatusContentViewForCanceled:model];
                break;

            case SentStatus_SENT:
                [self updateStatusContentViewForSent:model];
                break;

            case SentStatus_READ:
                [self updateStatusContentViewForRead:model];
                break;

            default:
                break;
        }
    });
}

- (void)updateStatusContentViewForSending:(JVHGMessageModel *)model {
    self.messageFailedStatusView.hidden = YES;

    if (self.messageActivityIndicatorView) {
        self.messageActivityIndicatorView.hidden = NO;

        if (self.messageActivityIndicatorView.isAnimating == NO) {
            [self.messageActivityIndicatorView startAnimating];
        }
    }
}

- (void)updateStatusContentViewForFailed:(JVHGMessageModel *)model {
    self.receiptStatusLabel.hidden = YES;
    if (1) {
        if (self.messageActivityIndicatorView) {
            self.messageActivityIndicatorView.hidden = NO;

            if (self.messageActivityIndicatorView.isAnimating == NO) {
                [self.messageActivityIndicatorView startAnimating];
            }
        }
    } else {
        self.messageFailedStatusView.hidden = NO;

        if (self.messageActivityIndicatorView) {
            self.messageActivityIndicatorView.hidden = YES;

            if (self.messageActivityIndicatorView.isAnimating == YES) {
                [self.messageActivityIndicatorView stopAnimating];
            }
        }
    }
}

- (void)updateStatusContentViewForCanceled:(JVHGMessageModel *)model {
    self.messageFailedStatusView.hidden = YES;

    if (self.messageActivityIndicatorView) {
        self.messageActivityIndicatorView.hidden = YES;

        if (self.messageActivityIndicatorView.isAnimating == YES) {
            [self.messageActivityIndicatorView stopAnimating];
        }
    }
}

- (void)updateStatusContentViewForSent:(JVHGMessageModel *)model {
    self.messageFailedStatusView.hidden = YES;

    if (self.messageActivityIndicatorView) {
        self.messageActivityIndicatorView.hidden = YES;

        if (self.messageActivityIndicatorView.isAnimating == YES) {
            [self.messageActivityIndicatorView stopAnimating];
        }
    }

    if (model.isCanSendReadReceipt) {
        self.receiptStatusLabel.hidden = NO;
    } else {
        self.receiptStatusLabel.hidden = YES;
    }
}

- (void)updateStatusContentViewForRead:(JVHGMessageModel *)model {
    BOOL isDisplayReadStatus = self.isDisplayReadStatus;
    BOOL isReadStatusType = model.conversationType == ConversationType_PRIVATE ||
        model.conversationType == ConversationType_Encrypted;

    if (!isDisplayReadStatus || !isReadStatusType) return;

    if (model.messageUId.length > 0) {
        self.receiptStatusLabel.hidden = NO;
    }

    self.messageFailedStatusView.hidden = YES;

    if (self.messageActivityIndicatorView) {
        self.messageActivityIndicatorView.hidden = YES;

        if (self.messageActivityIndicatorView.isAnimating == YES) {
            [self.messageActivityIndicatorView stopAnimating];
        }
    }
}

- (void)showBubbleBackgroundView:(BOOL)show {
    self.showBubbleBackgroundView = show;
    self.bubbleBackgroundView.userInteractionEnabled = show;

    if (show) {
        [self.messageContentView sendSubviewToBack:self.bubbleBackgroundView];
    } else {
        self.bubbleBackgroundView = nil;
    }
}

#pragma mark - Private Methods

- (void)setupMessageCellView {
    self.allowsSelection = YES;

    [self.baseContentView addSubview:self.portraitImageView];
    [self.baseContentView addSubview:self.nicknameLabel];
    [self.baseContentView addSubview:self.messageContentView];
    [self.baseContentView addSubview:self.statusContentView];
    [self.baseContentView addSubview:self.ttotheFrameView];
    [self.baseContentView addSubview:self.ttotheVIPTypeView];

    [self.statusContentView addSubview:self.messageFailedStatusView];
    [self.statusContentView addSubview:self.messageActivityIndicatorView];
    self.messageActivityIndicatorView.hidden = YES;
    [self.statusContentView addSubview:self.receiptStatusLabel];

    self.portraitImageView.layer.masksToBounds = YES;
}

- (void)registerMessageCellNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onUserInfoUpdate:)
                                                 name:@""
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onReceiptStatusUpdate:)
                                                 //: name:@"k_ttothe.com.can.cell.update.habibi.ayigu"
                                                 name:kTTotheString(kCherryPiranhaRestore)

                                               object:nil];

    [self registerFrameUpdateLayoutIfNeed];
    [self registerSizeUpdateLayoutIfNeed];
}

- (void)registerFrameUpdateLayoutIfNeed {
    __weak typeof(self) weakSelf = self;
    [self.messageContentView registerFrameChangedEvent:^(CGRect frame) {
        __strong typeof(weakSelf) strongSelf = weakSelf;

        if (strongSelf.model) {
            if (strongSelf.model.messageDirection == MessageDirection_SEND) {
                CGRect statusFrame = CGRectMake(frame.origin.x - 100 - 8, frame.origin.y, 100, frame.size.height);
                strongSelf.statusContentView.frame = statusFrame;

                if (strongSelf.model.conversationType == ConversationType_PRIVATE) {
                    strongSelf.receiptStatusLabel.frame = CGRectMake(100 - 32, statusFrame.size.height - 16, 32, 16);
                }

                strongSelf.messageFailedStatusView.frame = CGRectMake(statusFrame.size.width - 16, (statusFrame.size.height - 16) / 2, 16, 16);
                strongSelf.messageActivityIndicatorView.frame = strongSelf.messageFailedStatusView.frame;
            } else {
                CGRect statusFrame = CGRectMake(CGRectGetMaxX(frame) + 8, frame.origin.y, 100, frame.size.height);
                strongSelf.statusContentView.frame = statusFrame;
                strongSelf.messageFailedStatusView.frame = CGRectMake(0, (statusFrame.size.height - 16) / 2, 16, 16);
                strongSelf.messageActivityIndicatorView.frame = strongSelf.messageFailedStatusView.frame;
            }

            if (strongSelf.showBubbleBackgroundView) {

                strongSelf.bubbleBackgroundView.frame = strongSelf.messageContentView.bounds;
            }
        }
    }];
}

- (void)registerSizeUpdateLayoutIfNeed {
    __weak typeof(self) weakSelf = self;
    [self.messageContentView registerSizeChangedEvent:^(CGSize size) {
        __strong typeof(weakSelf) strongSelf = weakSelf;

        if (strongSelf.model) {
            CGRect rect = CGRectMake(0, 0, size.width, size.height);
            CGFloat protraitWidth = 1;

            if (strongSelf.model.messageDirection == MessageDirection_RECEIVE) {
                if (strongSelf.showPortrait) {
                    rect.origin.x = 12 + protraitWidth + 8;
                } else {
                    rect.origin.x = 12;
                }

                CGFloat messageContentViewY = 0;

                if (strongSelf.model.isDisplayNickname) {
                    messageContentViewY = 0 + 14 + 2;
                }

                rect.origin.y = messageContentViewY;
            } else {
                if (strongSelf.showPortrait) {
                    rect.origin.x = strongSelf.baseContentView.bounds.size.width - (size.width + 8 + protraitWidth + 12);
                } else {
                    rect.origin.x = strongSelf.baseContentView.bounds.size.width - (size.width + 12);
                }

                rect.origin.y = 0;
            }

            strongSelf.messageContentView.frame = rect;
        }
    }];
}

- (void)messageContentViewFrameDidChanged {
}

- (void)relayoutViewBy:(BOOL)show {
    CGFloat protraitWidth = 1;

    CGRect nicknameFrame = self.nicknameLabel.frame;
    CGRect contentFrame = self.messageContentView.frame;
    CGSize size = contentFrame.size;

    if (MessageDirection_RECEIVE == self.model.messageDirection) {
        CGFloat nameOffset_X = 0;

        if (self.showPortrait) {
            contentFrame.origin.x = 12 + protraitWidth + 8;
            nameOffset_X = self.portraitImageView.frame.origin.x + self.portraitImageView.bounds.size.width + 8;
        } else {
            contentFrame.origin.x = 12;
            nameOffset_X = self.portraitImageView.frame.origin.x;
        }

        nicknameFrame.origin = CGPointMake(nameOffset_X, 0);
        self.nicknameLabel.frame = nicknameFrame;
    } else { // owner
        if (self.showPortrait) {
            contentFrame.origin.x = self.baseContentView.bounds.size.width - (size.width + 8 + protraitWidth + 12);
        } else {
            contentFrame.origin.x = self.baseContentView.bounds.size.width - (size.width + 12);
        }
    }

    self.nicknameLabel.frame = nicknameFrame;
    self.messageContentView.frame = contentFrame;
    [self messageContentViewFrameDidChanged];
}

- (void)ttotheVIPUIConfig {
    self.ttotheVIPTypeView.hidden = YES;
    NSInteger heiyou = 0;
    if (self.model.messageDirection == MessageDirection_RECEIVE) {
        if (self.otherUser && self.otherUser.vipLevel>1) {
            self.ttotheVIPTypeView.hidden = NO;
            heiyou =  self.otherUser.vipLevel;
            self.ttotheVIPTypeView.left = self.messageContentView.right - self.ttotheVIPTypeView.width*0.5;
        }
    }
    else {
        if (self.mySelf && self.mySelf.vipLevel>1) {
            self.ttotheVIPTypeView.hidden = NO;
            
            heiyou =  self.mySelf.vipLevel;
            
            self.ttotheVIPTypeView.left = self.messageContentView.left - self.ttotheVIPTypeView.width*0.5;
            
        }
    }
    if (!self.ttotheVIPTypeView.hidden) {
        self.ttotheVIPTypeView.top = self.messageContentView.top - self.ttotheVIPTypeView.height*0.5;
        if (heiyou == 2 || heiyou == 3) {
            //: self.ttotheVIPTypeView.image = [SASToolUtils ttatheDirectoryImageWith:[NSString stringWithFormat:@"chat_viptype_%ld", (long)heiyou] cunhuaSize:CGSizeMake(18, 18)];


        }
        else {
            //: self.ttotheVIPTypeView.image = [SASToolUtils ttatheDirectoryImageWith:[NSString stringWithFormat:@"chat_viptype_%lu4", (unsigned long)self.model.messageDirection] cunhuaSize:CGSizeMake(18, 18)];


        }
    }
}

- (void)setCellAutoLayout {
    CGFloat protraitWidth = 1;
    CGFloat protraitHeight = 1;

    if (MessageDirection_RECEIVE == self.model.messageDirection) {
        [self.nicknameLabel setTextAlignment:NSTextAlignmentLeft];
        self.nicknameLabel.hidden = !self.model.isDisplayNickname;
        CGFloat portraitImageX = 12;
        self.portraitImageView.frame =
            CGRectMake(portraitImageX, 0, protraitWidth,
                       protraitHeight);

        if (self.showPortrait) {
            self.nicknameLabel.frame =
                CGRectMake(portraitImageX + self.portraitImageView.bounds.size.width + 8, 0, 200, 14);
        } else {
            self.nicknameLabel.frame =
                CGRectMake(portraitImageX, 0, 200, 14);
        }
    } else { // owner
        self.nicknameLabel.hidden = YES;
        CGFloat portraitImageX =
            self.baseContentView.bounds.size.width - (protraitWidth + 12);
        self.portraitImageView.frame =
            CGRectMake(portraitImageX, 0, protraitWidth,
                       protraitHeight);
        
    }
    self.ttotheFrameView.center = self.portraitImageView.center;

    self.messageContentView.contentSize = CGSizeMake(200, self.baseContentView.bounds.size.height - 14);
    [self updateStatusContentView:self.model];
}

- (void)onReceiptStatusUpdate:(NSNotification *)notification {
    // 更新消息状态
    NSDictionary *statusDic = notification.object;
    //: NSUInteger conversationType = [statusDic[@"conversationType"] integerValue];
    NSUInteger conversationType = [statusDic[kTTotheString(kEarthwormChewPapaw)] integerValue];

    //: NSString *targetId = statusDic[@"targetId"];
    NSString *targetId = statusDic[kTTotheString(kSpiderScanTargetid)];

    //: long messageId = [statusDic[@"messageId"] longValue];
    long messageId = [statusDic[kTTotheString(kUnpackDonkeyMessageid)] longValue];


    if (self.model.conversationType == conversationType && [self.model.targetId isEqualToString:targetId]) {
        dispatch_async(dispatch_get_main_queue(), ^{
            if (messageId == self.model.messageId) {
                self.model.isCanSendReadReceipt = YES;
                self.receiptStatusLabel.hidden = NO;
            } else {
                self.model.isCanSendReadReceipt = NO;
                self.receiptStatusLabel.hidden = YES;
            }
        });
    }
}

- (void)messageCellUpdateSendingStatusEvent:(NSNotification *)notification {
    JVMessageNotificationCellModel *notifyModel = notification.object;

    if (self.model.messageId == notifyModel.messageId) {
        if ([notifyModel.actionName isEqualToString:TTOTHE_CONVERSATION_CELL_STATUS_SEND_BEGIN_HEIYOU]) {
            self.model.sentStatus = SentStatus_SENDING;
            [self updateStatusContentView:self.model];
        } else if ([notifyModel.actionName isEqualToString:AYIGU_CONVERSATION_CELL_STATUS_SEND_FAILED_MIRCHI]) {
            self.model.sentStatus = SentStatus_FAILED;

            [self updateStatusContentView:self.model];
        //: } else if ([notifyModel.actionName isEqualToString:@"com.no.num.ennory"]) {
        } else if ([notifyModel.actionName isEqualToString:kTTotheString(kBearAroniaDash)]) {

            self.model.sentStatus = 80;
            [self updateStatusContentView:self.model];
        } else if ([notifyModel.actionName isEqualToString:CUNHUA_CONVERSATION_CELL_STATUS_SEND_CANCELED_CUNGU]) {
            self.model.sentStatus = SentStatus_CANCELED;
            [self updateStatusContentView:self.model];
        } else if ([notifyModel.actionName isEqualToString:FEIWU_CONVERSATION_CELL_STATUS_SEND_SUCCESS_TTATHE]) {
            if (self.model.sentStatus != SentStatus_READ) {
                self.model.sentStatus = SentStatus_SENT;
                [self updateStatusContentView:self.model];
            }
        } else if ([notifyModel.actionName isEqualToString:CUNGU_CONVERSATION_CELL_STATUS_SEND_PROGRESS_HEIYOU]) {
            self.model.sentStatus = SentStatus_SENDING;
            self.messageFailedStatusView.hidden = YES;
        } else if ([notifyModel.actionName isEqualToString:HEIYOU_CONVERSATION_CELL_STATUS_SEND_HASREAD_FEIWU] &&
                   (self.model.conversationType == ConversationType_PRIVATE ||
                    self.model.conversationType == ConversationType_Encrypted)) {
            self.model.sentStatus = SentStatus_READ;
            [self updateStatusContentView:self.model];
        } else if ([notifyModel.actionName isEqualToString:TTATHE_CONVERSATION_CELL_STATUS_SEND_READCOUNT_TTOTHE] &&
                   (self.model.conversationType == ConversationType_GROUP ||
                    self.model.conversationType == ConversationType_DISCUSSION)) {
            self.receiptStatusLabel.hidden = YES;
            [self updateStatusContentView:self.model];
        }
    }
}

- (void)sendMessageReadReceiptRequest:(NSString *)messageUId {
    RCMessage *message = [[RCCoreClient sharedCoreClient] getMessage:self.model.messageId];

    if (message) {
        if (!messageUId || [messageUId isEqualToString:@""]) {
            return;
        }

        [[RCCoreClient sharedCoreClient] sendReadReceiptRequest:message
                                                        success:^{
            self.model.isCanSendReadReceipt = NO;
            dispatch_async(dispatch_get_main_queue(), ^{
                self.receiptStatusLabel.hidden = YES;
                               if (!self.model.readReceiptInfo) {
                                   self.model.readReceiptInfo = [[RCReadReceiptInfo alloc] init];
                               }

                               self.model.readReceiptInfo.isReceiptRequestMessage = YES;


                           });
        }
                                                          error:^(RCErrorCode nErrorCode) {
            dispatch_async(dispatch_get_main_queue(), ^{
                //: kYOUFanToast(@"当前网络不可用，请检查你的网络设置");

                           });
        }];
    }
}

- (void)p_setReadStatus{

    if (self.model.messageDirection == MessageDirection_SEND && (self.model.sentStatus == SentStatus_SENT || self.model.sentStatus == SentStatus_READ)) {
        if (self.model.isCanSendReadReceipt) {
            self.receiptStatusLabel.hidden = NO;
        } else {
            self.receiptStatusLabel.hidden = YES;
        }
    }
    else{
        self.receiptStatusLabel.hidden = YES;
    }
}


- (void)p_showBubbleBackgroundView {
    if (self.showBubbleBackgroundView) {
        NSString *heiyou;
        if (MessageDirection_RECEIVE == self.model.messageDirection) {
            //: heiyou = @"bubble_right_1";
            heiyou = kTTotheString(kGrasshopperPapayaPack);

            if (self.otherUser && self.otherUser.vipLevel>1) {
                //: heiyou = [NSString stringWithFormat:@"bubble_bg_%ld", (long)self.otherUser.vipLevel];
                heiyou = [NSString stringWithFormat:kTTotheString(kMuleHawthornAbsorb), (long)self.otherUser.vipLevel];

            }
        } else {
            //: heiyou = @"bubble_left_1";
            heiyou = kTTotheString(kMulberryChopDeer);

            if (self.mySelf && self.mySelf.vipLevel>1) {
                //: heiyou = [NSString stringWithFormat:@"bubble_bg_%ld", (long)self.mySelf.vipLevel];
                heiyou = [NSString stringWithFormat:kTTotheString(kMuleHawthornAbsorb), (long)self.mySelf.vipLevel];

            }
        }
        UIImage *habibi = nil;
        self.bubbleBackgroundView.image = [GTLMessageBaseCell ayiguGetResizableImage:habibi];
    }
}


- (void)p_setUserInfo {
    JVHGMessageModel *model = self.model;
    
    if (model.conversationType == ConversationType_PRIVATE) {
        self.ttotheFrameView.hidden = YES;
        if (model.targetId.intValue == 1) {
            //: self.nicknameLabel.text = @"客服小U";
            self.nicknameLabel.text = kTTotheString(kFinchGreenAppleRun);

            //: [self.portraitImageView ttathe_setImageWith:@"app/logo"];

        } else {
            if (model.messageDirection == MessageDirection_SEND) {
                if (self.mySelf) {
                    [self.portraitImageView sd_setImageWithURL:self.mySelf.icon placeholderImage:nil];
                    self.ttotheFrameView.hidden = self.mySelf.vipLevel<4;
                } else {
                    // 报错
                    //: [self.portraitImageView ttathe_setImageWith:@"normal/defaut_avatar"];

                }
            } else {
                if (self.otherUser) {
                    [self.portraitImageView sd_setImageWithURL:self.otherUser.icon placeholderImage:nil];
                    self.ttotheFrameView.hidden = self.otherUser.vipLevel<4;
                } else {
                    //: [self.portraitImageView ttathe_setImageWith:@"normal/defaut_avatar"];

                }
            }
        }

    } else if (model.conversationType == ConversationType_SYSTEM) {
        //: self.nicknameLabel.text = @"系统通知";
        self.nicknameLabel.text = kTTotheString(kPaintWolfOpalApple);

        //: [self.portraitImageView ttathe_setImageWith:@"chat/normal/system_notifica"];

    }
    
    
}

#pragma mark - UserInfo Update
- (void)onUserInfoUpdate:(NSNotification *)notification {
//    NSDictionary *userInfoDic = notification.object;
//    dispatch_async(dispatch_get_main_queue(), ^{
//        if ([self.model.senderUserId isEqualToString:userInfoDic[@"userId"]]) {
//            if (self.model.conversationType == ConversationType_GROUP) {
//                //重新取一下混合的用户信息
//                RCUserInfo *userInfo = [[RCUserInfoCacheManager sharedManager] getUserInfo:self.model.senderUserId inGroupId:self.model.targetId];
//                RCUserInfo *tempUserInfo = [[RCUserInfoCacheManager sharedManager] getUserInfo:self.model.senderUserId];
//                userInfo.alias = tempUserInfo.alias;
//                [self updateUserInfoUI:userInfo];
//            } else if (self.model.messageDirection == MessageDirection_SEND) {
//                [self updateUserInfoUI:userInfoDic[@"userInfo"]];
//            } else if (self.model.conversationType != ConversationType_APPSERVICE &&
//                       self.model.conversationType != ConversationType_PUBLICSERVICE) {
//                if (self.model.conversationType == ConversationType_CUSTOMERSERVICE && self.model.content.senderUserInfo) {
//                    return;
//                }
//                [self updateUserInfoUI:userInfoDic[@"userInfo"]];
//            }
//        }
//    });
}



#pragma mark - Target Action
- (void)didClickMsgFailedView:(UIButton *)button {
    self.messageFailedStatusView.hidden = YES;
    self.model.sentStatus = SentStatus_SENDING;

}

- (void)enableShowReceiptView:(UIButton *)sender {
    if (!self.model.messageUId) {
        RCMessage *message = [[RCCoreClient sharedCoreClient] getMessage:self.model.messageId];

        if (message) {
            [self sendMessageReadReceiptRequest:message.messageUId];
        }
    } else {
        [self sendMessageReadReceiptRequest:self.model.messageUId];
    }
}

- (void)clickReceiptCountView:(id)sender {
}

- (void)tapUserPortaitEvent:(UIGestureRecognizer *)gestureRecognizer {
    __weak typeof(self) weakSelf = self;

}

- (void)longPressUserPortaitEvent:(UIGestureRecognizer *)gestureRecognizer {
    __weak typeof(self) weakSelf = self;


}

- (void)longPressedMessageContentView:(id)sender {

}

- (void)didTapMessageContentView {

}

- (NSInteger)ttotheImageIndex {
    _ttotheImageIndex = 1;
    if (MessageDirection_RECEIVE == self.messageDirection) {
        if (self.otherUser && self.otherUser.vipLevel>1) {
            _ttotheImageIndex = self.otherUser.vipLevel;
        }
    }
    else {
        if (self.mySelf && self.mySelf.vipLevel>1) {
            _ttotheImageIndex = self.mySelf.vipLevel;
        }
    }
    return _ttotheImageIndex;
}

#pragma mark - Getter && Setter

- (UILabel *)receiptStatusLabel {
    if (!_receiptStatusLabel) {
        _receiptStatusLabel = [[UILabel alloc] init];
        _receiptStatusLabel.textAlignment = NSTextAlignmentRight;
        //: _receiptStatusLabel.text = @"已读";
        _receiptStatusLabel.text = kTTotheString(kCrocodileKiwiPunch);

        _receiptStatusLabel.font = [UIFont systemFontOfSize:10 weight:UIFontWeightRegular];
//        _receiptStatusLabel.textColor = [UIColor colorWithRed:0 / 255.0 green:153 / 255.0 blue:255 / 255.0 alpha:1];
        _receiptStatusLabel.textColor = [UIColor colorWithRed:184 / 255.0 green:187 / 255.0 blue:190 / 255.0 alpha:1];
        _receiptStatusLabel.hidden = YES;
        UITapGestureRecognizer *clickReceiptCountView =
            [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickReceiptCountView:)];
        [_receiptStatusLabel addGestureRecognizer:clickReceiptCountView];
    }

    return _receiptStatusLabel;
}

- (UIActivityIndicatorView *)messageActivityIndicatorView {
    if (!_messageActivityIndicatorView) {
        _messageActivityIndicatorView =
            [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];

        _messageActivityIndicatorView.hidden = YES;
    }

    return _messageActivityIndicatorView;
}

- (UIButton *)messageFailedStatusView {
    if (!_messageFailedStatusView) {
        _messageFailedStatusView = [[UIButton alloc] init];
//        [_messageFailedStatusView setImage:[UIImage imageNamed:@"sendMsg_failed_tip"] forState:UIControlStateNormal];
        //: [_messageFailedStatusView ttathe_setImageWith:@"chat/normal/sendMsg_failed_tip" forState:UIControlStateNormal];


        _messageFailedStatusView.hidden = YES;
        [_messageFailedStatusView addTarget:self
                                     action:@selector(didClickMsgFailedView:)
                           forControlEvents:UIControlEventTouchUpInside];
    }

    return _messageFailedStatusView;
}

- (UIImageView *)portraitImageView {
    if (!_portraitImageView) {
        _portraitImageView = [[UIImageView alloc] init];
        //点击头像
        UITapGestureRecognizer *portraitTap =
            [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapUserPortaitEvent:)];
        portraitTap.numberOfTapsRequired = 1;
        portraitTap.numberOfTouchesRequired = 1;
        [_portraitImageView addGestureRecognizer:portraitTap];

        UILongPressGestureRecognizer *portraitLongPress =
            [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressUserPortaitEvent:)];
        [_portraitImageView addGestureRecognizer:portraitLongPress];

        _portraitImageView.userInteractionEnabled = YES;
    }

    return _portraitImageView;
}

- (UIImageView *)ttotheFrameView {
    if (!_ttotheFrameView) {
        _ttotheFrameView = [UIImageView new];
        //: _ttotheFrameView.image = [UIImage imageNamed:@"frame"];
        _ttotheFrameView.image = [UIImage imageNamed:kTTotheString(kBatDiceFrame)];


        _ttotheFrameView.hidden = YES;
    }
    return _ttotheFrameView;
}


- (UIImageView *)ttotheVIPTypeView {
    if (!_ttotheVIPTypeView) {
        _ttotheVIPTypeView = [UIImageView new];
        _ttotheVIPTypeView.size = CGSizeMake(18, 18);
        _ttotheVIPTypeView.hidden = YES;
    }
    return _ttotheVIPTypeView;
}

- (UILabel *)nicknameLabel {
    if (!_nicknameLabel) {
        _nicknameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _nicknameLabel.backgroundColor = [UIColor clearColor];
        [_nicknameLabel setFont:[UIFont systemFontOfSize:12 weight:UIFontWeightMedium]];
        [_nicknameLabel
         setTextColor:[UIColor grayColor]];
    }

    return _nicknameLabel;
}

- (UIView *)statusContentView {
    if (!_statusContentView) {
        _statusContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
        _statusContentView.backgroundColor = [UIColor clearColor];
    }

    return _statusContentView;
}

- (CXLGContentView *)messageContentView {
    if (!_messageContentView) {
        _messageContentView = [[CXLGContentView alloc] init];
        UILongPressGestureRecognizer *longPress =
            [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressedMessageContentView:)];
        [_messageContentView addGestureRecognizer:longPress];

        UITapGestureRecognizer *tap =
            [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapMessageContentView)];
        tap.numberOfTapsRequired = 1;
        tap.numberOfTouchesRequired = 1;
        self.ttotheTap = tap;
        [_messageContentView addGestureRecognizer:tap];
        _messageContentView.userInteractionEnabled = YES;
    }

    return _messageContentView;
}

- (UIImageView *)bubbleBackgroundView {
    if (!_bubbleBackgroundView) {
        _bubbleBackgroundView = [[UIImageView alloc] initWithFrame:CGRectZero];
        [self.messageContentView addSubview:self.bubbleBackgroundView];
    }

    return _bubbleBackgroundView;
}

#pragma mark - 获取城市JSON数据
- (NSArray *)ttotheVIPTextColors {
    static NSArray *ttothe = nil;
    if (!ttothe) {
        ttothe = @[[UIColor colorWithRed:246/255.0 green:147/255.0 blue:80/255.0 alpha:1], [UIColor colorWithRed:0/255.0 green:129/255.0 blue:174/255.0 alpha:1], [UIColor colorWithRed:155/255.0 green:67/255.0 blue:0/255.0 alpha:1]];
    }
    return ttothe;
}

- (UIColor *)heiyouTextColor {
    UIColor *heiyou;
    if (self.model.messageDirection == MessageDirection_SEND) {
        if (self.mySelf && self.mySelf.vipLevel>1) {
        }
        if (!heiyou) heiyou = UIColor.whiteColor;
    }
    else {
        if (self.otherUser && self.otherUser.vipLevel>1) {
        }
        if (!heiyou) heiyou = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1];
    }
    return heiyou;
}

@end
